<template>
    <div class="main-container">
        <div class="title">AI 智能助手</div>
        
        <div class="chat-container">
            <div class="message-list">
                <!-- 用户消息示例 -->
                <div class="message-item user-message" v-for="(message, index) in messages" :key="index" v-show="message.type === 'user'">
                    <div class="avatar">
                        <div class="avatar-icon user-avatar">U</div>
                    </div>
                    <div class="message-content">
                        <div class="message-bubble">{{ message.content }}</div>
                        <div class="message-time">{{ message.time }}</div>
                    </div>
                </div>
                
                <!-- AI消息示例 -->
                <div class="message-item ai-message" v-for="(message, index) in messages" :key="index" v-show="message.type === 'ai'">
                    <div class="avatar">
                        <div class="avatar-icon ai-avatar">AI</div>
                    </div>
                    <div class="message-content">
                        <div class="message-bubble">{{ message.content }}</div>
                        <div class="message-time">{{ message.time }}</div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="input-container">
            <div class="input-wrapper">
               
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

interface Message {
    type: 'user' | 'ai'
    content: string
    time: string
}

// 聊天消息列表
const messages = ref<Message[]>([
    {
        type: 'ai',
        content: '你好！我是AI助手，有什么可以帮助你的吗？',
        time: formatTime(new Date())
    },
    {
        type: 'user',
        content: 'plm系统是产品的生命周期管理，因此开发一个plm系统的基本功能有哪些，请系统化整理，plm系统是产品的生命周期管理，因此开发一个plm系统的基本功能有哪些，请系统化整理，plm系统是产品的生命周期管理，因此开发一个plm系统的基本功能有哪些，请系统化整理，plm系统是产品的生命周期管理，因此开发一个plm系统的基本功能有哪些，请系统化整理',
        time: formatTime(new Date())
    }
])

// 输入框消息
const inputMessage = ref('')

// 格式化时间
function formatTime(date: Date): string {
    const hours = date.getHours().toString().padStart(2, '0')
    const minutes = date.getMinutes().toString().padStart(2, '0')
    return `${hours}:${minutes}`
}

// 发送消息
function sendMessage() {
    if (!inputMessage.value.trim()) return
    
    // 添加用户消息
    const userMessage: Message = {
        type: 'user',
        content: inputMessage.value,
        time: formatTime(new Date())
    }
    messages.value.push(userMessage)
    
    // 清空输入框
    const userInput = inputMessage.value
    inputMessage.value = ''
    
    // 模拟AI回复
    setTimeout(() => {
        const aiMessage: Message = {
            type: 'ai',
            content: `我收到了你的消息: "${userInput}"。这是一个模拟的AI回复。`,
            time: formatTime(new Date())
        }
        messages.value.push(aiMessage)
    }, 1000)
}
</script>

<style lang="scss" scoped>
.main-container {
    flex: 1;
    background-color: #1e293b;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding-left: 200px;
    padding-right: 200px;
    
    .title {
        height: 50px;
        color: #e2e8f0;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 20px;
        font-weight: 800;
        border-bottom: 1px solid #334155;
    }

    .chat-container {
        flex: 1;
        overflow: hidden;
        position: relative;
        padding: 20px 0;
        
        .message-list {
            height: 100%;
            overflow-y: auto;
            padding: 0 10px;
            scrollbar-width: thin;
            scrollbar-color: rgba(226, 232, 240, 0.2) transparent;
            
            &::-webkit-scrollbar {
                width: 6px;
            }
            
            &::-webkit-scrollbar-thumb {
                background-color: rgba(226, 232, 240, 0.2);
                border-radius: 3px;
            }
        }
        
        .message-item {
            display: flex;
            margin-bottom: 20px;
            
            &.user-message {
                flex-direction: row-reverse;
                
                .message-content {
                    align-items: flex-end;
                    margin-right: 10px;
                    margin-left: 0;
                }
                
                .message-bubble {
                    background-color: #4f46e5;
                    border-radius: 18px 18px 4px 18px;
                }
            }
            
            &.ai-message {
                .message-bubble {
                    background-color: #2d3748;
                    border-radius: 18px 18px 18px 4px;
                }
            }
        }
        
        .avatar {
            flex-shrink: 0;
            
            .avatar-icon {
                width: 40px;
                height: 40px;
                border-radius: 50%;
                display: flex;
                justify-content: center;
                align-items: center;
                font-size: 14px;
                font-weight: bold;
                
                &.user-avatar {
                    background-color: #4f46e5;
                    color: #e2e8f0;
                }
                
                &.ai-avatar {
                    background-color: #6366f1;
                    color: #e2e8f0;
                }
            }
        }
        
        .message-content {
            display: flex;
            flex-direction: column;
            margin-left: 10px;
            max-width: 70%;
        }
        
        .message-bubble {
            padding: 12px 16px;
            color: #e2e8f0;
            word-break: break-word;
            line-height: 1.5;
        }
        
        .message-time {
            font-size: 12px;
            color: rgba(226, 232, 240, 0.5);
            margin-top: 4px;
        }
    }

    .input-container {
        padding: 20px 0;
        border-top: 1px solid #334155;
    }
}
</style>